package com.atguigu.gmall.product.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.vo.CategoryTreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.junit.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "内部接口,被web-all服务远程调用的产品分类的接口")
@RestController
@RequestMapping("/api/inner/rpc/product")
public class CategoryRpcController {
    @Autowired
    BaseCategory1Service baseCategory1Service;

    /**
     * 向商品详情页返回分类信息
     * @return
     */
    @GetMapping("category/view/{c3Id}")
    public Result getCategoryTreeByCategory3Id(@PathVariable("c3Id") Long c3Id) {
        CategoryTreeVo vo = baseCategory1Service.getCategoryTreeByCategory3Id(c3Id);
        return Result.ok(vo);
    }

    @ApiOperation("获取分类的全部数据并组织成树形结构")
    @GetMapping("category/tree")
    public Result getCategoryTree() {
        List<CategoryTreeVo> vos =  baseCategory1Service.getCategoryTree();
        return Result.ok(vos);
    }
}
